package cc.sjfx.sharedoc.db.bmob;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import cc.sjfx.sharedoc.bean.ReplyInfo;
import cc.sjfx.sharedoc.bmob.FileInfo4Examination;
import cc.sjfx.sharedoc.cache.UserCache;
import cn.bmob.v3.BmobObject;

@SuppressWarnings("serial")
public class Examination extends BmobObject {
	private String downloadUrl;
	private String content;
	private Integer major;
	private Integer school;
	private String publisher;
	private String title;
	private Integer date_year;
	private Integer date_month;
	private Integer date_day;
	private List<FileInfo4Examination> file;
	private Long date;
	private Integer type;
	private String user;
	private Integer replyNum;
	public long getDate() {

		return date;
	}

	public void setDate(long date) {
		this.date = date;
	}

	public int getReplyNum() {
		if(replyNum==null)
			return 0;
		return replyNum;
	}

	public void setReplyNum(Integer replyNum) {
		this.replyNum = replyNum;
	}
	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public JSONArray getFileJson() throws JSONException {
		JSONArray jsonArray = new JSONArray();
		if (file != null) {
			for (int i = 0; i < file.size(); i++) {
				jsonArray.put(file.get(i).file2Json());
			}
		}

		return jsonArray;
	}

	public int getType() {
		if (type == null) {
			return 0;
		}
		return type;
	}

	public void setType(int type) {
		this.type = new Integer(type);
	}
	/*
	 * 试题分享
	 */
	public Examination(String user, String downloadUrl, String content,
			int major, int school, String publisher, String title,
			int date_year, int date_month, int date_day, int type) {
		super();
		this.user = user;
		this.downloadUrl = downloadUrl;
		this.content = content;
		this.major = major;
		this.school = school;
		this.publisher = publisher;
		this.title = title;
		this.date_year = date_year;
		this.date_month = date_month;
		this.date_day = date_day;
		this.type = type;
		// this.file = file;
	}
	/*
	 * 问答
	 */
	public Examination(String title, Integer major, String content,List<FileInfo4Examination> file) {
		super();
		this.content = content;
		this.major = major;
		this.title = title;
		this.type = 2;
		this.user = UserCache.user.getUsername();
		this.file=file;
	}
	/*
	 * 拼试卷
	 */
	public Examination(String content, Integer major, Integer school,
			String title, Integer date_year, Integer date_month,
			Integer date_day, Long date) {
		super();
		this.user = UserCache.user.getUsername();
		this.type = 3;
		this.content = content;
		this.major = major;
		this.school = school;
		this.title = title;
		this.date_year = date_year;
		this.date_month = date_month;
		this.date_day = date_day;
		this.date = date;
	}

	public Examination() {

	}

	public int getDate_year() {
		if (date_year != null)
			return date_year.intValue();
		return 0;
	}

	public void setDate_year(int date_year) {
		this.date_year = new Integer(date_year);
	}

	public int getDate_month() {
		if (date_month != null)
			return date_month.intValue();
		return 0;
	}

	public void setDate_month(int date_month) {
		this.date_month = new Integer(date_month);
	}

	public int getDate_day() {
		if (date_day != null)
			return date_day.intValue();
		return 0;
	}

	public void setDate_day(int date_day) {
		this.date_day = new Integer(date_day);
	}

	public String getDownloadUrl() {
		return downloadUrl;
	}

	public void setDownloadUrl(String downloadUrl) {
		this.downloadUrl = downloadUrl;
	}

	public List<FileInfo4Examination> getFile() {
		return file;
	}

	public void setFile(List<FileInfo4Examination> file) {
		this.file = file;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getMajor() {
		if (major != null)
			return major.intValue();
		return 0;
	}

	public void setMajor(int major) {
		this.major = new Integer(major);
	}

	public int getSchool() {
		if (school != null) {
			return school.intValue();
		}

		return 0;
	}

	public void setSchool(int school) {
		this.school = new Integer(school);
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
}
